package com.tjshop.android.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.tjshop.android.EventDetailActivity;
import com.tjshop.android.R;
import com.tjshop.android.model.activityInfo;
import com.tjshop.android.util.ImageLoaderUtils;

import java.util.List;

/**
 * Created by gytaiSSD on 2015/1/15.
 */
public class activity_adapter extends BaseAdapter {
	private LayoutInflater inflater;
	List<activityInfo> activityList;
	private DisplayImageOptions options;
	private Context mContext;

	public activity_adapter(Context context, List<activityInfo> clist,
			LayoutInflater inflater) {
		this.inflater = inflater;
		activityList = clist;
		this.mContext = context;
	}

	@Override
	public int getCount() {
		return activityList.size();
	}

	@Override
	public Object getItem(int i) {
		return activityList.get(i);
	}

	@Override
	public long getItemId(int i) {
		return i;
	}

	@Override
	public View getView(int i, View view, ViewGroup viewGroup) {
		view = inflater.inflate(R.layout.inc_discover_event_item, null);
		LinearLayout frame = (LinearLayout) view.findViewById(R.id.LinearFrame);
		ImageView img = (ImageView) view.findViewById(R.id.activity_img);
		TextView title = (TextView) view.findViewById(R.id.activity_title);
		TextView time = (TextView) view.findViewById(R.id.activity_time);
		TextView join_num = (TextView) view
				.findViewById(R.id.activity_join_num);
		TextView sum = (TextView) view.findViewById(R.id.activity_sum);
		title.setText(activityList.get(i).getDesc());
		time.setText(activityList.get(i).getStart_time() + "-"
				+ activityList.get(i).getEnd_time());
		join_num.setText("参加人数：" + activityList.get(i).getTotal_user());
		String shangxian = "0";
		if (activityList.get(i).getHeadcount().equals("0")) {
			shangxian = "无上限";
		} else {
			shangxian = "人数上限：" + activityList.get(i).getHeadcount();
		}
		sum.setText(shangxian);
		ImageLoaderUtils.getInstance(mContext).displayImage(
				activityList.get(i).getIcon(), img);
		final int index = i;
		frame.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(inflater.getContext(),
						EventDetailActivity.class);
				intent.putExtra("coupon_id", activityList.get(index)
						.getEvent_id());
				inflater.getContext().startActivity(intent);
			}
		});
		return view;
	}
}
